<?php
namespace app\admin\controller;
use think\Controller;
use think\captcha\Captcha;

class Index extends controller
{
	//首页
    public function index()
    {
        
        return $this->fetch();
    }

    //登陆页
    public function Login()
    {  
       
       return $this->fetch();
    }

    //验证登陆
    public function checklogin(){
        $username=input("post.username");
        $password=input("post.password");
        $verify=input("post.verify");
       
        if(empty($username)){
             return json(["code"=>201,"msg"=>"用户名不能为空"]);exit;
        }
        if(empty($password)){
             return json(["code"=>201,"msg"=>"密码不能为空"]);exit;
        }
        if(empty($verify)){
             return json(["code"=>201,"msg"=>"验证码不能为空"]);exit;
        }
        // 检测输入的验证码是否正确
        $captcha = new Captcha();       
 
        if(!$captcha->check($verify))
        {
             return json(["code"=>201,"msg"=>"验证码输入错误"]);exit;
        }
       
        
        return model('Index')->checkLogin($username,$password);
       
    }

    //验证码
    public function getverify(){
    	$captcha = new Captcha();       
        return $captcha->entry();
    }
}
